package com.guigu.ssyx.product.controller;


import com.guigu.ssyx.common.result.Result;
import com.guigu.ssyx.product.entity.Attr;
import com.guigu.ssyx.product.service.AttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品属性 前端控制器
 * </p>
 *
 * @author liuyang
 * @since 2025-09-10
 */
@RestController
@RequestMapping("/admin/product/attr")

public class AttrController {

    @Autowired
    private AttrService attrService;

    @GetMapping("{attrGroupId}")
    public Result index(@PathVariable Long attrGroupId){

     List<Attr>  list = attrService.getAttrListByGroupId(attrGroupId);
     return Result.ok(list);

    }

    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id){
        Attr attr = attrService.getById(id);
        return Result.ok(attr);
    }

    @PostMapping("save")
    public Result save(@RequestBody Attr attr){
        attrService.save(attr);
        return Result.ok(null);
    }

    @PutMapping("update")
    public Result updateById(@RequestBody Attr attr){
        attrService.updateById(attr);
        return Result.ok(null);
    }
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id){
        attrService.removeById(id);
        return Result.ok(null);
    }

    @PostMapping("batchRemove")
    public Result batchRemove(@RequestBody List<Long> idList){
        attrService.removeByIds(idList);
        return Result.ok(null);
    }



}

